<template>
	<div class="s_resource">
		<ul class="clear" v-loading="loading">
			<template  v-for="(item ,index) of resourceList">
				<li class="i_hResourcesLsD fl" :key="index">
					<div class="i_hResourcesT clear">
						<!-- <a href="###"	 title="2018年高考语文资料">{{item.name}}.{{item.postfix}}</a> -->
						<a @click="openResource(item)"  :title="item.name">{{item.name}}.{{item.postfix}}</a>
						<span class="fr">
							<img :src="`${BASE_URL}/static/index/images/format/resourceicon${item.file_type}.png`">
						</span>
					</div>
					<div class="i_hResourcesS clear">
						<div class="i_hScore fl clear">
							<el-rate
							  v-model="item.scores_half"
							  disabled 
							  disabled-void-color="#c5c5c5"
							  text-color="#ff9900">
							</el-rate>
							<i>{{item.scores}}</i>	
						</div>
						<div class="i_hCollect fr">
							<img src="../../../../public/images/xin.png" class="xin_icon">
							<strong>{{item.favs}}</strong>
						</div>
					</div>
					<div class="i_rUser">
						<a>
							<span>
								<img :src="BASE_URL+item.u_avatar_path">
							</span>
							{{item.u_name}}
						</a>
					</div>
				</li>
			</template>
			
			
		</ul>
		<el-pagination v-if="parseInt(total_number) > size"
	      @current-change="changePage"
	      :current-page="page"
	      :page-size="size"
	      layout="prev, pager, next"
	      :total="total_number">
	    </el-pagination>

	    <div class="dependent" v-if="placeholder">
	    	<i class="ipng image_state01"></i>
	    	<p>
	    		还没发现任何相关的内容哦~
	    	</p>
	    </div>
	</div>
</template>

<script>
	export default {
		name: '',
		data() {
			return {
				scoreValue:3,
				listResourceParam:{
					create_id: this.$route.query.id,
					size: 12,
					page: 1,
					data_type: 2,
					authonity: 1
				},

				create_id: this.$route.query.id,
				size: 12,
				page: 1,
				data_type: 2,

				total_number:0,
				resourceList:[],
				placeholder: false,
				loading: true
			}
		},
		created(){
	       this.getResourceList();
		},
		methods: {
			/*
				跳转到优课专辑模块查看视频
			 */
			openResource(item){
				let host = sessionStorage.getItem( 'host' )
				let redirectParams = sessionStorage.getItem( 'redirect_params' )
				let link = `${this.BASE_URL}${redirectParams}&host=${host}&routerUrl=/home/resourceDetail&id=${item.id}`
				window.open(link)
			},
			//分页改变
            changePage(val) {
            	this.page = val;
    			this.getResourceList();
            },

            getResourceList(){
            	let success = (data=>{
            		this.resourceList = data.data.data;
            		for (var i = this.resourceList.length - 1; i >= 0; i--) {
            			this.resourceList[i].scores_half = this.resourceList[i].scores/2;
            		}

            		this.total_number = data.data.data_sum;

            		this.loading = false
            		this.resourceList.length === 0
            		? this.placeholder = true
            		: this.placeholder = false
            	})

            	if (this.$g.user_id == this.create_id) {
            		this.$ajax.get('api/Resource/resource',{
            			params: {
            				
            				create_id: this.create_id,
            				size: this.size,
            				page: this.page,
            				data_type: 2,
            				status: '1,2,3',
            			},
            			func:{success:success}
            		})
            	}else{
            		this.$ajax.get('api/Resource/resource',{
            			params: {
            				
            				create_id: this.create_id,
            				size: this.size,
            				page: this.page,
            				data_type: 2,
            				status: '1',
            				authonity:1
            			},
            			func:{success:success}
            		})
            	}

            	//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
            	// this.$ajax.get('api/Resource/resource',{
            	// 	params: this.listResourceParam,
            	// 	func:{success:success}
            	// })
            },
           
		}
	}
</script>